package com.bzkj.web.controller.basicInfo.check;

import com.bzkj.basicinfo.domain.check.WmsCheckTaskEntity;
import com.bzkj.basicinfo.service.check.WmsCheckTaskService;
import com.bzkj.common.annotation.LogB;
import com.bzkj.common.core.controller.BaseController;
import com.bzkj.common.core.domain.AjaxResult;
import com.bzkj.common.core.page.TableDataInfo;
import com.bzkj.common.enums.BusinessType;
import com.bzkj.common.utils.ServletUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import static com.bzkj.common.core.page.TableSupport.PAGE_NUM;
import static com.bzkj.common.core.page.TableSupport.PAGE_SIZE;

/**
 * WMS复核任务Controller
 *
 * @author system
 * @date 2025-10-22
 */
@RestController
@RequestMapping("/wms/check")
public class WmsCheckTaskController extends BaseController {

    @Autowired
    private WmsCheckTaskService checkTaskService;

    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('wms:check:list')")
    public TableDataInfo list(WmsCheckTaskEntity entity) {
        Integer pageNum = ServletUtils.getParameterToInt(PAGE_NUM, 1);
        Integer pageSize = ServletUtils.getParameterToInt(PAGE_SIZE, 10);
        return checkTaskService.getCheckTaskList(entity, pageNum, pageSize);
    }

    @GetMapping("/{id}")
    @PreAuthorize("@ss.hasPermi('wms:check:query')")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(checkTaskService.getCheckTaskDetail(id));
    }

    @PostMapping("/create")
    @PreAuthorize("@ss.hasPermi('wms:check:add')")
    @LogB(title = "创建复核任务", businessType = BusinessType.INSERT)
    public AjaxResult create(@RequestParam Long outboundOrderId, @RequestParam(required = false) String checkType) {
        return toAjax(checkTaskService.createCheckTask(outboundOrderId, checkType));
    }

    @PutMapping("/assign/{id}")
    @PreAuthorize("@ss.hasPermi('wms:check:assign')")
    @LogB(title = "分配复核任务", businessType = BusinessType.UPDATE)
    public AjaxResult assign(@PathVariable Long id, @RequestParam String assignedUser) {
        return toAjax(checkTaskService.assignCheckTask(id, assignedUser));
    }

    @PutMapping("/complete/{id}")
    @PreAuthorize("@ss.hasPermi('wms:check:complete')")
    @LogB(title = "完成复核任务", businessType = BusinessType.UPDATE)
    public AjaxResult complete(@PathVariable Long id) {
        return toAjax(checkTaskService.completeCheckTask(id));
    }

    @DeleteMapping("/{id}")
    @PreAuthorize("@ss.hasPermi('wms:check:remove')")
    @LogB(title = "删除复核任务", businessType = BusinessType.DELETE)
    public AjaxResult remove(@PathVariable Long id) {
        return toAjax(checkTaskService.deleteCheckTask(id));
    }
}
